/**
 * 
 */
package sccs.core;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import ar.edu.sccs.dao.CaseDTO;
import ar.edu.sccs.entities.Case;
import ar.edu.sccs.monitoring.logging.SCCSLogger;
import ar.edu.sccs.util.Constants;

/**
 * @author Fernando Clase que representa un Caso optimizado para su uso en la UI
 */
public class CaseUI extends CaseDTO {

	static Logger logger = SCCSLogger.getLogger(CaseUI.class);

	private final String strAbstract = Constants.Clazz.ABSTRACT;
	private final String strFinal = Constants.Clazz.FINAL;
	private final String strStrictfp = Constants.Clazz.STRICTFP;
	private final String strNative = Constants.Clazz.NATIVE;
	private final String strStatic = Constants.Clazz.STATIC;
	private final String strSynchronized = Constants.Clazz.SYNCRONIZED;

	private boolean classPackageRender;
	private boolean classImplementsRender;
	private boolean classExtendRender;
	private boolean classVisibilityRender;
	private boolean classIsFinalRender;
	private boolean classIsStrictfpRender;
	private boolean classIsAbstractRender;
	private boolean methodExceptionsRender;
	private boolean methodVisibilityRender;
	private boolean methodIsAbstractRender;
	private boolean methodIsFinalRender;
	private boolean methodIsStrictfpRender;
	private boolean methodIsNativeRender;
	private boolean methodIsStaticRender;
	private boolean methodIsSynchronizedRender;

	private Double similarity;
	private Double calification;

	public CaseUI(Case cbrCase, Case targetCase) {
		super(cbrCase);

		this.similarity = cbrCase.getSimilarity();

		this.setClassImplements(replaceFieldSeparator(this.getClassImplements()));
		this.setMethodParams(replaceFieldSeparator(this.getMethodParams()));
		this.setMethodExceptions(replaceFieldSeparator(this.getMethodExceptions()));

		this.classPackageRender = StringUtils.isNotBlank(targetCase.getDimension(Constants.Dimension.Class.PACKAGE).getStringValue());
		this.classImplementsRender = StringUtils.isNotBlank(targetCase.getDimension(Constants.Dimension.Class.IMPLEMENTS).getStringValue());
		this.classExtendRender = StringUtils.isNotBlank(targetCase.getDimension(Constants.Dimension.Class.EXTEND).getStringValue());
		this.classVisibilityRender = targetCase.getDimension(Constants.Dimension.Class.PUBLIC).getValue() != null
				|| targetCase.getDimension(Constants.Dimension.Class.PROTECTED).getValue() != null
				|| targetCase.getDimension(Constants.Dimension.Class.PRIVATE).getValue() != null;
		this.classIsFinalRender = targetCase.getDimension(Constants.Dimension.Class.FINAL).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.FINAL).getBooleanValue() == true;
		this.classIsStrictfpRender = targetCase.getDimension(Constants.Dimension.Class.STRICTFP).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.STRICTFP).getBooleanValue() == true;
		this.classIsAbstractRender = targetCase.getDimension(Constants.Dimension.Class.ABSTRACT).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.ABSTRACT).getBooleanValue() == true;
		this.methodExceptionsRender = StringUtils.isNotBlank(targetCase.getDimension(Constants.Dimension.Method.EXCEPTIONS).getStringValue());
		this.methodVisibilityRender = targetCase.getDimension(Constants.Dimension.Method.PUBLIC).getValue() != null
				|| targetCase.getDimension(Constants.Dimension.Method.PROTECTED).getValue() != null
				|| targetCase.getDimension(Constants.Dimension.Method.PRIVATE).getValue() != null;
		this.methodIsAbstractRender = targetCase.getDimension(Constants.Dimension.Method.ABSTRACT).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.ABSTRACT).getBooleanValue() == true;
		this.methodIsFinalRender = targetCase.getDimension(Constants.Dimension.Method.FINAL).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.FINAL).getBooleanValue() == true;
		this.methodIsStrictfpRender = targetCase.getDimension(Constants.Dimension.Method.STRICTFP).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.STRICTFP).getBooleanValue() == true;
		this.methodIsNativeRender = targetCase.getDimension(Constants.Dimension.Method.NATIVE).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.NATIVE).getBooleanValue() == true;
		this.methodIsStaticRender = targetCase.getDimension(Constants.Dimension.Method.STATIC).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.STATIC).getBooleanValue() == true;
		this.methodIsSynchronizedRender = targetCase.getDimension(Constants.Dimension.Method.SYNCRONIZED).getValue() != null
				&& targetCase.getDimension(Constants.Dimension.Method.SYNCRONIZED).getBooleanValue() == true;
	}

	private String replaceFieldSeparator(String str) {
		if (str == null)
			return str;
		return str.replaceAll("\\|", ", ");
	}

	/**
	 * @return the classPackageRender
	 */
	public boolean isClassPackageRender() {
		return classPackageRender;
	}

	/**
	 * @param classPackageRender
	 *            the classPackageRender to set
	 */
	public void setClassPackageRender(boolean classPackageRender) {
		this.classPackageRender = classPackageRender;
	}

	/**
	 * @return the classImplementsRender
	 */
	public boolean isClassImplementsRender() {
		return classImplementsRender;
	}

	/**
	 * @param classImplementsRender
	 *            the classImplementsRender to set
	 */
	public void setClassImplementsRender(boolean classImplementsRender) {
		this.classImplementsRender = classImplementsRender;
	}

	/**
	 * @return the classExtendRender
	 */
	public boolean isClassExtendRender() {
		return classExtendRender;
	}

	/**
	 * @param classExtendRender
	 *            the classExtendRender to set
	 */
	public void setClassExtendRender(boolean classExtendRender) {
		this.classExtendRender = classExtendRender;
	}

	/**
	 * @return the classVisibilityRender
	 */
	public boolean isClassVisibilityRender() {
		return classVisibilityRender;
	}

	/**
	 * @param classVisibilityRender
	 *            the classVisibilityRender to set
	 */
	public void setClassVisibilityRender(boolean classVisibilityRender) {
		this.classVisibilityRender = classVisibilityRender;
	}

	/**
	 * @return the classIsFinalRender
	 */
	public boolean isClassIsFinalRender() {
		return classIsFinalRender;
	}

	/**
	 * @param classIsFinalRender
	 *            the classIsFinalRender to set
	 */
	public void setClassIsFinalRender(boolean classIsFinalRender) {
		this.classIsFinalRender = classIsFinalRender;
	}

	/**
	 * @return the classIsStrictfpRender
	 */
	public boolean isClassIsStrictfpRender() {
		return classIsStrictfpRender;
	}

	/**
	 * @param classIsStrictfpRender
	 *            the classIsStrictfpRender to set
	 */
	public void setClassIsStrictfpRender(boolean classIsStrictfpRender) {
		this.classIsStrictfpRender = classIsStrictfpRender;
	}

	/**
	 * @return the classIsAbstractRender
	 */
	public boolean isClassIsAbstractRender() {
		return classIsAbstractRender;
	}

	/**
	 * @param classIsAbstractRender
	 *            the classIsAbstractRender to set
	 */
	public void setClassIsAbstractRender(boolean classIsAbstractRender) {
		this.classIsAbstractRender = classIsAbstractRender;
	}

	/**
	 * @return the methodExceptionsRender
	 */
	public boolean isMethodExceptionsRender() {
		return methodExceptionsRender;
	}

	/**
	 * @param methodExceptionsRender
	 *            the methodExceptionsRender to set
	 */
	public void setMethodExceptionsRender(boolean methodExceptionsRender) {
		this.methodExceptionsRender = methodExceptionsRender;
	}

	/**
	 * @return the methodVisibilityRender
	 */
	public boolean isMethodVisibilityRender() {
		return methodVisibilityRender;
	}

	/**
	 * @param methodVisibilityRender
	 *            the methodVisibilityRender to set
	 */
	public void setMethodVisibilityRender(boolean methodVisibilityRender) {
		this.methodVisibilityRender = methodVisibilityRender;
	}

	/**
	 * @return the methodIsAbstractRender
	 */
	public boolean isMethodIsAbstractRender() {
		return methodIsAbstractRender;
	}

	/**
	 * @param methodIsAbstractRender
	 *            the methodIsAbstractRender to set
	 */
	public void setMethodIsAbstractRender(boolean methodIsAbstractRender) {
		this.methodIsAbstractRender = methodIsAbstractRender;
	}

	/**
	 * @return the methodIsFinalRender
	 */
	public boolean isMethodIsFinalRender() {
		return methodIsFinalRender;
	}

	/**
	 * @param methodIsFinalRender
	 *            the methodIsFinalRender to set
	 */
	public void setMethodIsFinalRender(boolean methodIsFinalRender) {
		this.methodIsFinalRender = methodIsFinalRender;
	}

	/**
	 * @return the methodIsStrictfpRender
	 */
	public boolean isMethodIsStrictfpRender() {
		return methodIsStrictfpRender;
	}

	/**
	 * @param methodIsStrictfpRender
	 *            the methodIsStrictfpRender to set
	 */
	public void setMethodIsStrictfpRender(boolean methodIsStrictfpRender) {
		this.methodIsStrictfpRender = methodIsStrictfpRender;
	}

	/**
	 * @return the methodIsNativeRender
	 */
	public boolean isMethodIsNativeRender() {
		return methodIsNativeRender;
	}

	/**
	 * @param methodIsNativeRender
	 *            the methodIsNativeRender to set
	 */
	public void setMethodIsNativeRender(boolean methodIsNativeRender) {
		this.methodIsNativeRender = methodIsNativeRender;
	}

	/**
	 * @return the methodIsStaticRender
	 */
	public boolean isMethodIsStaticRender() {
		return methodIsStaticRender;
	}

	/**
	 * @param methodIsStaticRender
	 *            the methodIsStaticRender to set
	 */
	public void setMethodIsStaticRender(boolean methodIsStaticRender) {
		this.methodIsStaticRender = methodIsStaticRender;
	}

	/**
	 * @return the methodIsSynchronizedRender
	 */
	public boolean isMethodIsSynchronizedRender() {
		return methodIsSynchronizedRender;
	}

	/**
	 * @param methodIsSynchronizedRender
	 *            the methodIsSynchronizedRender to set
	 */
	public void setMethodIsSynchronizedRender(boolean methodIsSynchronizedRender) {
		this.methodIsSynchronizedRender = methodIsSynchronizedRender;
	}

	/**
	 * @return the similarity
	 */
	public Double getSimilarity() {
		return similarity;
	}

	/**
	 * @param similarity
	 *            the similarity to set
	 */
	public void setSimilarity(Double similarity) {
		this.similarity = similarity;
	}

	/**
	 * @return the calification
	 */
	public Double getCalification() {
		return calification;
	}

	/**
	 * @param calification
	 *            the calification to set
	 */
	public void setCalification(Double calification) {
		this.calification = calification;
	}

	/**
	 * @return the strAbstract
	 */
	public String getStrAbstract() {
		return strAbstract;
	}

	/**
	 * @return the strFinal
	 */
	public String getStrFinal() {
		return strFinal;
	}

	/**
	 * @return the strStrictfp
	 */
	public String getStrStrictfp() {
		return strStrictfp;
	}

	/**
	 * @return the strNative
	 */
	public String getStrNative() {
		return strNative;
	}

	/**
	 * @return the strStatic
	 */
	public String getStrStatic() {
		return strStatic;
	}

	/**
	 * @return the strSynchronized
	 */
	public String getStrSynchronized() {
		return strSynchronized;
	}
}